﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;

namespace QuanLyRapChieuPhim
{
    public partial class frmSPlash : Form
    {
        public frmSPlash()
        {
            InitializeComponent();
        }
        private static Thread _splashThread;
        private static frmSPlash _splashForm;


        // Show the Splash Screen (Loading...)      
        public static void ShowSplash()
        {
            if (_splashThread == null)
            {
                // show the form in a new thread            
                _splashThread = new Thread(new ThreadStart(DoShowSplash));
                _splashThread.IsBackground = true;
                _splashThread.Start();
            }
        }

        private static void DoShowSplash()
        {
            if (_splashForm == null)
            {
                _splashForm = new frmSPlash();
                _splashForm.StartPosition = FormStartPosition.CenterScreen;
                _splashForm.TopMost = true;
            }
            // create a new message pump on this thread (started from ShowSplash)        
            Application.Run(_splashForm);
        }

        // Close the splash (Loading...) screen    
        public static void CloseSplash()
        {
            // Need to call on the thread that launched this splash        
            if (_splashForm.InvokeRequired)
                _splashForm.Invoke(new MethodInvoker(CloseSplash));
            else
                Application.ExitThread();
        }

        private void frmSPlash_Load(object sender, EventArgs e)
        {
            timer1.Enabled = true;
            timer1.Start();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (progressBar1.Value == 100)
            {
                timer1.Enabled = false;
                progressBar1.Visible = false;
                CloseSplash();
            }
            else
            {
                progressBar1.Value = progressBar1.Value + 10;
            }
        }
    }
}
